package com.yingside.gui;

import javax.swing.*;
import java.awt.*;

public class TestNullLayout extends JFrame {
    private JButton btn1,btn2,btn3,btn4,btn5,btn6;

    public TestNullLayout(){
        this.setTitle("自定义布局窗口");

        //设置窗口的位置和大小可以合并为一句代码
        this.setBounds(300,300,400,400);

        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


        //自定义布局，直接把布局管理器设置为null
        //自定义布局管理器需要自己设定每个组件的尺寸和位置
        this.setLayout(null);
        btn1 = new JButton("1");
        btn1.setBounds(50,50,30,30);
        btn2 = new JButton("2");
        btn2.setBounds(50,100,30,30);
        btn3 = new JButton("3");
        btn3.setBounds(50,150,30,30);
        btn4 = new JButton("4");
        btn4.setBounds(50,200,30,30);
        btn5 = new JButton("5");
        btn5.setBounds(50,250,30,30);
        btn6 = new JButton("6");
        btn6.setBounds(50,300,30,30);

        this.add(btn1);
        this.add(btn2);
        this.add(btn3);
        this.add(btn4);
        this.add(btn5);
        this.add(btn6);



        //this.setVisible(true);
    }

    public static void main(String[] args) {
        TestNullLayout ff = new TestNullLayout();
        ff.setVisible(true);
    }
}
